package com.ojoin.trade.supplyloan_core.web.service.impl;

import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.utils.TimeUtils;
import com.ojoin.trade.common.web.dao.BaseDao;
import com.ojoin.trade.common.web.service.impl.BaseServiceImpl;
import com.ojoin.trade.supplyloan_core.web.dao.TbSlSupplyloginCheckDao;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUser;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlSupplyloginCheck;
import com.ojoin.trade.supplyloan_core.web.service.TbSlSupplyloginCheckService;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 15-10-27
 * Time: 下午2:33
 * To change this template use File | Settings | File Templates.
 */
@Service
public class TbSlSupplyloginCheckServiceImpl extends BaseServiceImpl<TbSlSupplyloginCheck> implements TbSlSupplyloginCheckService {
   @Autowired
 
   private TbSlSupplyloginCheckDao dao;

    @Override
    protected BaseDao<TbSlSupplyloginCheck> getBaseDao() {
        return dao;
    }
    
     
     
//    @Override
//    public void addTbSlSupplyloginCheck(int idOfTbMerchantUser, String platformName, int idOfPlatformUser, String username, String password, int checkStatus, String memo) throws BusinessException {
//        TbSlSupplyloginCheck checkvo=new TbSlSupplyloginCheck();
//        checkvo.setIdOfTbMerchantUser(idOfTbMerchantUser);
//        checkvo.setIdOfPlatformUser(idOfPlatformUser);
//        checkvo.setPlatformName(platformName);
//        checkvo.setCheckStatus(checkStatus);
//        checkvo.setMemo(memo);
//        checkvo.setCheckDate(CommonUtils.getCurDate());
//        checkvo.setUsername(username);
//        checkvo.setPassword(password);
//        ( ( TbSlSupplyloginCheckDao)this.getBaseDao()) .insertTbSlloginCheck(checkvo);
//
//    }

    @Override
    public void insertTbSlSupplyloginCheck(TbSlSupplyloginCheck checkvo) throws BusinessException {
        ( ( TbSlSupplyloginCheckDao)this.getBaseDao()) .insertTbSlloginCheck(checkvo);
    } 

    @Override
    public TbSlSupplyloginCheck queryTbSlSupplyloginCheckByJoinid(int joinid) throws BusinessException {
        return ( ( TbSlSupplyloginCheckDao)this.getBaseDao()).queryTbSlLogincheck(joinid,TimeUtils.getCurDate());
    }

    @Override
	/**
     * 查询电商平台不可登陆账号
     * @param joinuserNo
     * @throws BusinessException
     */ 
 
	public List<TbSlSupplyloginCheck> querySupplyChainPlatformUserCanNotLogin(
			int joinuserNo, String time) throws BusinessException { 
		return  ( List<TbSlSupplyloginCheck>)(( TbSlSupplyloginCheckDao)this.getBaseDao()).querySupplyChainPlatformUserCanNotLogin(joinuserNo,time);
	}


    
	@Override
	public boolean querySupplyChainPlatformUserCanLogin(int joinuserNo,
			String time) throws BusinessException {
		boolean flag = true ;
	   List<TbSlSupplyloginCheck> li = dao.selectAll();
	   
	   if(null != li && li.size() > 0 ){
		   Iterator<TbSlSupplyloginCheck> it = li.iterator();
		   while(it.hasNext()){
			   TbSlSupplyloginCheck tbsl = it.next();
			   if(tbsl.getCheckStatus() == 0){  
				   return false ; 
			   }
		   }
	   }else {
		   flag = false ;
	   }
		
		
		return flag;
	}
   
	@Override
	public TbSlSupplyloginCheck queryTbSlSupplyloginCheckById(int id)
			throws BusinessException {
		return dao.selectById(id);
	}



	@Override
	public TbSlSupplyloginCheck getLoginCheckVOByPlatformUser(TbSlPlatformUser platformUser) {
		TbSlSupplyloginCheck checkvo = new TbSlSupplyloginCheck();
		checkvo.setIdOfPlatformUser(platformUser.getId());
		checkvo.setIdOfTbMerchantUser(platformUser.getIdOfTbMerchantUser());
		checkvo.setPlatformName(platformUser.getPlatformName());
		checkvo.setUsername(platformUser.getUsername());
		checkvo.setPassword(platformUser.getPassword());
		checkvo.setCheckDate(TimeUtils.getCurDate());
		
		return checkvo;
	}

	

}
